/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Nov 13, 2013  4:51:17 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.interfaces
 * File Name : ProjectController.java
 * TODO
 */
package com.tis.interfaces;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.tis.interfaces.commons.ServletCommon;
import com.tis.interfaces.commons.XmlResultback;
import promis.utility.CommonService;
import apps.ApplConfiguration;
import apps.business.process.commons.project.ProjectProcessing;
import java.util.Date;
import java.util.Map;
import jpa.entitys.synchro.staging.AGenDesc;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Nov 13, 2013 : 4:51:17 PM 
 * CreateBy=Chatree Siangklom
 * 
 * ProjectController
 * TODO
 */
@Controller
@RequestMapping(value=ProjectController.url)
public class ProjectController extends ServletCommon {
	
	private static final Logger logging = LoggerFactory.getLogger(ProjectController.class);	
	public static final String url = "/servlet/common/project";
	public static final String uri = "/interfaces/common";

	@RequestMapping(method = RequestMethod.GET)
	public HttpEntity<byte[]> index(HttpServletRequest request, HttpServletResponse response) {
		logging.info("Welcome ProjectController--->index");
		XmlResultback xmlResultback = new XmlResultback(promis.utility.ProcessModule.PROJECT.toString(), null, new Date());
		try {
			
	    	Map mapValue = super.initParam(request);
	    	AGenDesc aGenDesc = new ApplConfiguration().GetInterfaceChannel(
																				CommonService.ConvertStringToBigDecimal("1001"), 
																				CommonService.ConvertStringToBigDecimal("1002"), 
																				promis.utility.BusinessModule.COMMONS.toString(), 
																				promis.utility.ProcessModule.PROJECT.toString());
	    	if(CommonService.IsNullRString(aGenDesc.getValue3()).equals("Q")){
		    	new apps.promis.out.common.SyncQueueAction().PutQueue(	promis.utility.BusinessModule.COMMONS.toString(), 
		    															promis.utility.ProcessModule.PROJECT.toString(),
		    															null,
																		processAction,
		    														 	mapValue);
		    	
		    	
		    	xmlResultback.setMsgcode("QS");
		    	xmlResultback.setMsgDescription("Queue Success");
		    	
	    	}else if(CommonService.IsNullRString(aGenDesc.getValue3()).equals("D")){
		    	ProjectProcessing object = new ProjectProcessing();
		    	if(action.toUpperCase().equals(promis.utility.InterfaceAction.project.PER_PLANT.toString())){
		    		object.Processing(sapPlantCode);	
		    	}		    		
		    	else if(action.toUpperCase().equals(promis.utility.InterfaceAction.project.PER_PROJECT.toString()))
		    	{
		    		object.ProcessingByProjectCode(company, project);
		    		xmlResultback.setMsgcode("PS");
			    	xmlResultback.setMsgDescription("Processing Success.");
		    	}
	    	}
	    } catch (Exception e) {
	    	xmlResultback.setMsgcode("EE");
			xmlResultback.setMsgDescription(e.getMessage());
			
	    	e.printStackTrace();
	    	logging.error("Error:" + e.getMessage());
		}
		
		return(ToXml(xmlResultback));
	}

}
